集成带有So文件的三方应用时,如果不处理so文件,会导致应用打不开的情况,所以针对这些so文件需要做一些额外的处理。
方法一
把解压的lib文件放在makefile 目录,通过遍历lib目录一个个编译到目标文件夹
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := GaoDeMap
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_PRIVILEGED_MODULE := true
LOCAL_SRC_FILES := apk/amapauto.apk
LOCAL_MULTILIB := 32
JNI_LIBS :=
$(foreach FILE,$(shell find $(LOCAL_PATH)/lib/armeabi-v7a/ -name *.so), $(eval JNI_LIBS += $(FILE)))
LOCAL_PREBUILT_JNI_LIBS := $(subst $(LOCAL_PATH),,$(JNI_LIBS))
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)
文件目录
|____GaodeMap
| |____Android.mk
| |____apk
| | |____amapauto.apk
| |____.DS_Store
| |____lib
| | |____armeabi-v7a
| | | |____libapssdk.so
| | | |____libGNet.so
| | | |____libcocklogic.so
|____Android.mk
|____.DS_Store
|____Baidu
| |____Android.mk
| |____apk
| | |____BaiduMapAuto.apk
| |____.DS_Store
| |____lib
| | |____armeabi
| | | |____libbd_etts.so
| | | |____libBaiduTraceSDK_v2_1_12.so
| | | |____libBDSpeechDecoder_V1.so
|____Ximalaya
| |____Android.mk
| |____apk
| | |____ximalaya.apk
| |____.DS_Store
| |____lib
| | |____armeabi
| | | |____libxmediaplayer_x.so
| | | |____libvideo.so
|____QingTing
| |____Android.mk
| |____apk
| | |____QingTingFm.apk
| |____.DS_Store
| |____lib
| | |____armeabi
| | | |____libtnet-2.1.20.1-agoo.so
| | | |____libcocklogic.so
| | | |____libgifimage.so
| | | |____libRSSupport.so
| | | |____librsjni.so
|____QQMusic
| |____Android.mk
| |____apk
| | |____qqmusiccar.apk
| |____.DS_Store
| |____lib
| | |____armeabi
| | | |____libdesdecrypt.so
| | | |____libqm_native_decoder_ape.so
方法二
使用@符号,自动把APK内容解压
LOCAL_PATH := $(call my-dir)
MY_ABI := armeabi
include $(CLEAR_VARS)
LOCAL_MODULE := BaiduMap
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_SRC_FILES := BaiduMapAuto.apk
LOCAL_PREBUILT_JNI_LIBS := \
@lib/$(MY_ABI)/libapp_BaiduNaviApplib.so \
@lib/$(MY_ABI)/libapp_BaiduVIlib.so \
@lib/$(MY_ABI)/libaudiomessage-jni.so \
@lib/$(MY_ABI)/libBaiduTraceSDK_v2_1_12.so \
@lib/$(MY_ABI)/libbd_etts.so \
@lib/$(MY_ABI)/libBDSpeechDecoder_V1.so \
@lib/$(MY_ABI)/libbdtts.so \
@lib/$(MY_ABI)/libcrash_analysis.so \
@lib/$(MY_ABI)/libetts_domain_data_builder.so \
@lib/$(MY_ABI)/libgnustl_shared.so \
@lib/$(MY_ABI)/liblocnaviSDK.so \
@lib/$(MY_ABI)/liblocSDK6a.so \
@lib/$(MY_ABI)/libmapautolicense.so
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)
编译输出内容
PRODUCT_COPY_FILES device/qcom/common/media/media_profiles.xml:system/etc/media_profiles.xml ignored.
PRODUCT_COPY_FILES device/qcom/common/media/media_codecs.xml:system/etc/media_codecs.xml ignored.
No private recovery resources for TARGET_DEVICE msm8937_32
620+0 records in
620+0 records out
634880 bytes (635 kB, 620 KiB) copied, 0.00572881 s, 111 MB/s
Starting build with ninja
ninja: Entering directory `.'
[ 75% 3/4] target Prebuilt: BaiduMap (out/target/product/msm8937_32/obj/APPS/BaiduMap_intermediates/package.apk)
Archive: out/target/product/msm8937_32/obj/APPS/BaiduMap_intermediates/package.apk
inflating: out/target/product/msm8937_32/obj/APPS/BaiduMap_intermediates/uncompressedlibs/lib/armeabi/libaudiomessage-jni.so
inflating: out/target/product/msm8937_32/obj/APPS/BaiduMap_intermediates/uncompressedlibs/lib/armeabi/libbdtts.so
inflating: out/target/product/msm8937_32/obj/APPS/BaiduMap_intermediates/uncompressedlibs/lib/armeabi/libgnustl_shared.so
inflating: out/target/product/msm8937_32/obj/APPS/BaiduMap_intermediates/uncompressedlibs/lib/armeabi/libbd_etts.so
inflating: out/target/product/msm8937_32/obj/APPS/BaiduMap_intermediates/uncompressedlibs/lib/armeabi/libcrash_analysis.so
inflating: out/target/product/msm8937_32/obj/APPS/BaiduMap_intermediates/uncompressedlibs/lib/armeabi/libapp_BaiduVIlib.so
inflating: out/target/product/msm8937_32/obj/APPS/BaiduMap_intermediates/uncompressedlibs/lib/armeabi/liblocSDK6a.so
inflating: out/target/product/msm8937_32/obj/APPS/BaiduMap_intermediates/uncompressedlibs/lib/armeabi/liblocnaviSDK.so
inflating: out/target/product/msm8937_32/obj/APPS/BaiduMap_intermediates/uncompressedlibs/lib/armeabi/libapp_BaiduNaviApplib.so
inflating: out/target/product/msm8937_32/obj/APPS/BaiduMap_intermediates/uncompressedlibs/lib/armeabi/libBDSpeechDecoder_V1.so
inflating: out/target/product/msm8937_32/obj/APPS/BaiduMap_intermediates/uncompressedlibs/lib/armeabi/libetts_domain_data_builder.so
inflating: out/target/product/msm8937_32/obj/APPS/BaiduMap_intermediates/uncompressedlibs/lib/armeabi/libBaiduTraceSDK_v2_1_12.so
inflating: out/target/product/msm8937_32/obj/APPS/BaiduMap_intermediates/uncompressedlibs/lib/armeabi/libmapautolicense.so
deleting: lib/armeabi/libaudiomessage-jni.so
deleting: lib/armeabi/libbdtts.so
deleting: lib/armeabi/libgnustl_shared.so
deleting: lib/armeabi/libbd_etts.so
deleting: lib/armeabi/libcrash_analysis.so
deleting: lib/armeabi/libapp_BaiduVIlib.so
deleting: lib/armeabi/liblocSDK6a.so
deleting: lib/armeabi/liblocnaviSDK.so
deleting: lib/armeabi/libapp_BaiduNaviApplib.so
deleting: lib/armeabi/libBDSpeechDecoder_V1.so
deleting: lib/armeabi/libetts_domain_data_builder.so
deleting: lib/armeabi/libBaiduTraceSDK_v2_1_12.so
deleting: lib/armeabi/libmapautolicense.so
adding: lib/armeabi/libBDSpeechDecoder_V1.so (stored 0%)
adding: lib/armeabi/libBaiduTraceSDK_v2_1_12.so (stored 0%)
adding: lib/armeabi/libapp_BaiduNaviApplib.so (stored 0%)
adding: lib/armeabi/libapp_BaiduVIlib.so (stored 0%)
adding: lib/armeabi/libaudiomessage-jni.so (stored 0%)
adding: lib/armeabi/libbd_etts.so (stored 0%)
adding: lib/armeabi/libbdtts.so (stored 0%)
adding: lib/armeabi/libcrash_analysis.so (stored 0%)
adding: lib/armeabi/libetts_domain_data_builder.so (stored 0%)
adding: lib/armeabi/libgnustl_shared.so (stored 0%)
adding: lib/armeabi/liblocSDK6a.so (stored 0%)
adding: lib/armeabi/liblocnaviSDK.so (stored 0%)
adding: lib/armeabi/libmapautolicense.so (stored 0%)
[100% 4/4] Install: out/target/product/msm8937_32/system/app/BaiduMap/BaiduMap.apk
make: Leaving directory '/wkspc/meiglink/LA.UM.5.6'
#### make completed successfully (20 seconds) ####
方法三
@
符号有时候并不会生效,所以就需要把so手动解压lib目录到mk的同级目录,然后执行make
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
MY_ABI := armeabi
LOCAL_MODULE := XimalayaFM
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_SRC_FILES := XimalayaFM.apk
LOCAL_MULTILIB := 32
LOCAL_PREBUILT_JNI_LIBS := \
lib/$(MY_ABI)/libBugly.so \
lib/$(MY_ABI)/libchat.so \
lib/$(MY_ABI)/libdetect.so \
lib/$(MY_ABI)/libencrypt.so \
lib/$(MY_ABI)/liblive.so \
lib/$(MY_ABI)/libLivenessModule.so \
lib/$(MY_ABI)/liblocSDK7b.so \
lib/$(MY_ABI)/libmain.so \
lib/$(MY_ABI)/libmediadatacryto.so \
lib/$(MY_ABI)/libmsc.so \
lib/$(MY_ABI)/libndkbitmap.so \
lib/$(MY_ABI)/libpl_droidsonroids_gif.so \
lib/$(MY_ABI)/librecord.so \
lib/$(MY_ABI)/libsgmain.so \
lib/$(MY_ABI)/libsgnocaptcha.so \
lib/$(MY_ABI)/libsgsecuritybody.so \
lib/$(MY_ABI)/libsoundtouch.so \
lib/$(MY_ABI)/libttEncrypt.so \
lib/$(MY_ABI)/libvideo.so \
lib/$(MY_ABI)/libweibosdkcore.so \
lib/$(MY_ABI)/libweike.so \
lib/$(MY_ABI)/libxmediaplayer_x.so \
lib/$(MY_ABI)/libxmediaplayer.so \
lib/$(MY_ABI)/libxmediaplayerv7.so \
lib/$(MY_ABI)/0kb.so \
lib/$(MY_ABI)/libNewMediaProcessor.so \
lib/$(MY_ABI)/libaar_alijtca_plus.so \
lib/$(MY_ABI)/libandroid-asr.so \
lib/$(MY_ABI)/libdubscore-jni-armeabi-v7a.so \
lib/$(MY_ABI)/libfb.so \
lib/$(MY_ABI)/libfolly_json.so \
lib/$(MY_ABI)/libframesequence.so \
lib/$(MY_ABI)/libgifimage.so \
lib/$(MY_ABI)/libglog.so \
lib/$(MY_ABI)/libglog_init.so \
lib/$(MY_ABI)/libgnustl_shared.so \
lib/$(MY_ABI)/libicu_common.so \
lib/$(MY_ABI)/libijkffmpeg-armeabi-v7a.so \
lib/$(MY_ABI)/libijkplayer-armeabi-v7a.so \
lib/$(MY_ABI)/libijksdl-armeabi-v7a.so \
lib/$(MY_ABI)/libimagepipeline.so \
lib/$(MY_ABI)/libjsc.so \
lib/$(MY_ABI)/libmarsxlog.so \
lib/$(MY_ABI)/libmm.so \
lib/$(MY_ABI)/libmyspinnative.so \
lib/$(MY_ABI)/libprivatedata.so \
lib/$(MY_ABI)/libreactnativejni.so \
lib/$(MY_ABI)/librtmp-jni.so \
lib/$(MY_ABI)/libsoundbalance.so \
lib/$(MY_ABI)/libstlport_shared.so \
lib/$(MY_ABI)/libucrop.so \
lib/$(MY_ABI)/libutility.so \
lib/$(MY_ABI)/libxmffcmd-armeabi-v7a.so \
lib/$(MY_ABI)/libxmrecorder-armeabi-v7a.so \
lib/$(MY_ABI)/libyoga.so \
lib/$(MY_ABI)/libzegoliveroom.so
LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/app
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)
方法四
但是手动解压非常麻烦,所以就修改脚本进行处理。
因为带so的APK在编译过程中会先解压缩如out/target/product/xxx/obj/APPS/LauncherB_intermediates/uncompressedlibs/lib/armeabi/libfacialproc_jni.so
所以编译的时候会遍历这个目录:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
MY_ABI := armeabi
LOCAL_MODULE := XimalayaFM
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_SRC_FILES := XimalayaFM.apk
APK_LibList :=
$(subst $(LOCAL_PATH)/uncompressedlibs,,\
$(foreach FILE,$(shell unzip -l $(LOCAL_PATH)/$(LOCAL_SRC_FILES) 'lib/*.so'|grep 'arm'),$(eval APK_LibList += $(FILE))))
#$(info $(APK_LibList))
ARM64_LIB := $(findstring arm64-v8a,$(APK_LibList))
ARMV7A_LIB := $(findstring armeabi-v7a,$(APK_LibList))
ARM_LIB := $(findstring armeabi,$(APK_LibList))
ARCH_LIB := $(if $(TARGET_ARCH),$(if $(ARM64_LIB),$(ARM64_LIB),$(if $(ARMV7A_LIB),$(ARMV7A_LIB),$(ARM_LIB))),$(if $(ARMV7A_LIB),$(ARMV7A_LIB),$(ARM_LIB)))
TARGET_BIT := $(if $(findstring arm64,$(ARCH_LIB)),64,32)
$(info $(ARCH_LIB) $(TARGET_BIT))
PRIVATE_EMBEDDED_JNI_LIBS := 'lib/$(ARCH_LIB)/*.so'
JNI_LIBS :=
$(foreach FILE,$(shell if unzip -l $(LOCAL_PATH)/$(LOCAL_SRC_FILES) $(PRIVATE_EMBEDDED_JNI_LIBS) > /dev/null ; then \
rm -rf $(LOCAL_PATH)/uncompressedlibs && \
mkdir $(LOCAL_PATH)/uncompressedlibs; \
unzip $(LOCAL_PATH)/$(LOCAL_SRC_FILES) $(PRIVATE_EMBEDDED_JNI_LIBS) -d $(LOCAL_PATH)/uncompressedlibs > /dev/null && \
find $(LOCAL_PATH)/uncompressedlibs -name *.so; \
fi),$(eval JNI_LIBS += $(FILE)))
LOCAL_PREBUILT_JNI_LIBS := $(subst $(LOCAL_PATH),,$(JNI_LIBS))
LOCAL_MULTILIB := $(TARGET_BIT)
LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/app
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)
方法四有时候也会出问题,出现编译失败的情况,方法三是最保险的。